package org.one.stone.soup.grfxML.plugin.text;

import org.one.stone.soup.grfxML.DataPlugin;
import org.one.stone.soup.grfxML.DataSize;
import org.one.stone.soup.grfxML.DataString;
import org.one.stone.soup.grfxML.DataText;
import org.one.stone.soup.grfxML.GrfxMLEngine;
import org.one.stone.soup.grfxML.plugin.SimplePlugin;
import org.one.stone.soup.grfxML.plugin.grfxMLCaster;
import org.one.stone.soup.mjdb.data.field.CompareException;
import org.one.stone.soup.mjdb.data.field.DataLinker;
import org.one.stone.soup.mjdb.data.field.Field;
import org.one.stone.soup.mjdb.data.field.LockException;

public class TextConstraint extends SimplePlugin {

	private static final int ARG_WIDTH = 0;
	private static final int ARG_LINES = 1;
	private static final int ARG_TEXT = 2;

	DataSize width = new DataSize();
	DataSize height = new DataSize();
	DataText text = new DataText();
/**
 * SuperString constructor comment.
 */
public TextConstraint(GrfxMLEngine engine) {
	super(engine);
}
/**
 * compare method comment.
 */
public int compare(Field target) throws CompareException {
	return 0;
}
/**
 * getClone method comment.
 */
public DataPlugin getClone() {
	return null;
}
/**
 * getClone method comment.
 */
public DataPlugin getClone(String path) {
	return null;
}
/**
 * getValue method comment.
 */
public String getValue(String name) {
	return null;
}
/**
 * initialize method comment.
 */
public void initialize()
{
}
/**
 * process method comment.
 */
public void process()
{
 try{

//	if(text.hasChanged())
//	{
	if(width.getValue()>0)
	{
		for(int loop=0;loop<text.size();loop++)
		{
			String line = text.get(loop).getValue();

			if(line.length()>width.getValue())
			{
				text.get(loop).setValue( line.substring(0,width.getValue()),this );
				if(text.size()<loop+2)
					text.add( new DataString(),this );

				text.get(loop+1).setValue( line.substring(width.getValue())+text.get(loop+1).getValue(),this );
			}
		}
	}

 	if(height.getValue()>0)
 	{
		while(text.size()>height.getValue())
		{
			text.remove( text.size()-1,this );
		}
 	}
//	}

 }catch(LockException le){}
}
/**
 * register method comment.
 */
public void register(DataLinker store)
{
	width	=	grfxMLCaster.cast(width,getArg(width,ARG_WIDTH,store));
	height	=	grfxMLCaster.cast(height,getArg(height,ARG_LINES,store));
	text	=	grfxMLCaster.cast(text,getArg(text,ARG_TEXT,store));
}
/**
 * replace method comment.
 */
public void replace(org.one.stone.soup.mjdb.data.field.Field oldObj, org.one.stone.soup.mjdb.data.field.Field newObj)
{
	width	=	grfxMLCaster.replace(width,oldObj,newObj);
	height	=	grfxMLCaster.replace(height,oldObj,newObj);
	text	=	grfxMLCaster.replace(text,oldObj,newObj);
}
/**
 * stop method comment.
 */
public void stop() {}
}
